\begin{lstlisting}[frame=shadowbox, language=C, breaklines=true, basicstyle=\footnotesize]
#Aca hay que implementar la logica para imprimir el buffer al reves

#include <mips/regdef.h>
#include <sys/syscall.h>

#define TAM_FRAME       56

#define SS_BUFFER       60
#define SS_TAMANO       56

#define POS_SRA_RA      48
#define POS_SRA_FP      44
#define POS_SRA_GP      40

#define LA_POS_FIN_MAS  32
#define LA_BUFF_MAS_POS 28
#define LA_RESTA_POS    24
#define LA_POS_FINAL    20
#define LA_POS          16

#define FIELD_SEPARATOR '\n'
#define STDOUT          1

.data 
mj1: .asciiz ``m1\n''
mj2: .asciiz ``m2\n''
mj3: .asciiz ``m3\n''

.text
.align 2
.globl imprimir
.ent imprimir

imprimir:
   .frame        $fp,TAM_FRAME,ra
   .set noreorder
   .cpload       t9
   .set reorder
   subu          sp,sp,TAM_FRAME
   .cprestore POS_SRA_GP
   sw            $fp, POS_SRA_FP(sp)
   sw            ra, POS_SRA_RA(sp)
   move          $fp,sp

#Argument Building Area
   sw            a0, SS_BUFFER(sp)#buffer
   sw            a1, SS_TAMANO(sp) #tamano

   beq           a1,zero,salida1 #si el contador esta en 0


#Guardo variables locales - Local Area
   sw            zero, LA_POS (sp) #pos
   subu          t1, a1 , 1
   sw            t1, LA_POS_FINAL (sp) #pos_final

while:
   b             buscar_fin_linea
ret:
   beq           t2, -1 , end_while 
   lw            t7, SS_BUFFER(sp) # recupero la posicion del buffer
   addu          t3, t2, 1 #buffer + 1
   addu          t3, t7, t3 #buffer + pos + 1 
   subu          t4, t1,t2 #pos_final - pos

#Preparo la llamada al write
   sw            t2, LA_POS(sp) #pos
   sw            t1, LA_POS_FINAL(sp) #pos_final
   sw            t3, LA_BUFF_MAS_POS(sp)#buffer + pos + 1 - guardo
   sw            t4, LA_RESTA_POS (sp) #pos_final - pos - guardo


   li            a0, STDOUT
   lw            a1, LA_BUFF_MAS_POS(sp)#buffer + pos + 1
   lw            a2, LA_RESTA_POS (sp)
   la            t9, write
   jal           t9

#recupero las variables

   lw            t2, LA_POS (sp) #pos
   lw            t1, LA_POS_FINAL (sp) #pos_final
   lw            t3, LA_BUFF_MAS_POS(sp)#buffer + pos + 1 
   lw            t4, LA_RESTA_POS (sp) #pos_final - pos 

   bne           v0, t4,error #verifico si escribi la cantidad de caracteres pedida
   move          t1, t2
   b             while

end_while:
   addu          t5, t1, 1

   sw            t2, LA_POS (sp) #pos
   sw            t1, LA_POS_FINAL (sp) #pos_final
   sw            t5, LA_POS_FIN_MAS(sp) # pos_final +1

   lw            a1, SS_BUFFER(sp) #buffer
   li            a0, STDOUT
   lw            a2, LA_POS_FIN_MAS(sp)
   la            t9, write
   jal           t9

   lw            t5, LA_POS_FIN_MAS(sp) # pos_final +1

#Cargo los registros para la salida
salida1:
   move          sp, $fp
   lw            ra, POS_SRA_RA(sp)
   lw            $fp, POS_SRA_FP(sp)
   addu          sp, sp, TAM_FRAME

   bne           v0, t5, error
#salida en caso correcto
   li            v0,0
   j             ra

#salida en caso de error
error:
   li            v0, -1
   j             ra 


buscar_fin_linea:
   #t2 contador
   #t1 tamanio del buffer
   #t3 buffer+contador -> address
   #t4 buffer[contador]   
   lw            a0, SS_BUFFER(sp) #coloco en la posicion del buffer
   
   subu          t2, t1, 1
   addu          t3,a0,t2   
   for: # (t2 = t1 -1; t2 >= 0, t2--)    
      beq        t2,-1, ret   #termino el for
      lbu        t4,0(t3) #cargo el byte en el q estoy parado   
      if: 
         beq     t4,FIELD_SEPARATOR, ret
         subu    t2,t2,1 #i--
         subu    t3,t3,1
    b for
   
.end imprimir
\end{lstlisting}
